﻿using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Mvc.RazorPages;
using OnWork.DataCenter.DAL.DataCenter;
using OnWork.DataCenter.Shared.Data;

namespace OnWork.DataCenter.Shared.Shared
{
    /// <summary>
    ///
    /// </summary>
    public sealed partial class MainLayout
    {
        public bool UseTabSet { get; set; } = true;

        private string Theme { get; set; } = "";

        private bool IsOpen { get; set; }

        private bool IsFixedHeader { get; set; } = false;

        private bool IsFixedFooter { get; set; } = false;

        private bool IsFullSide { get; set; } = true;

        private bool ShowFooter { get; set; } = false;

        private List<MenuItem>? Menus { get; set; }

        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();
            if (Menus == null)
            {
                Menus = GetIconSideMenuItems();
            }
        }

        protected override void OnAfterRender(bool firstRender)
        {
            base.OnAfterRender(firstRender);
            if (firstRender) //只更新一次
            {
                //Menus = GetIconSideMenuItems();
                //StateHasChanged();
            }
        }

        private static List<MenuItem> GetIconSideMenuItems()
        {
            var menusDataSource = new List<MenuItem>()
            {
                new MenuItem() { Text = "数据源配置", Icon = "fa-solid fas fa-database",IsCollapsed = false,
                    Items= new List<MenuItem>{
                        new MenuItem (){ Text="数据库",Url="/DataSource/DataBaseConfig",Icon="fas fa-database",IsCollapsed = false,},
                        new MenuItem (){ Text="MQTT服务器",Url="/DataSource/MQTTConfig" ,Icon="fas fa-bullhorn"},
                         new MenuItem (){ Text="MQTT订阅",Url="/DataSource/MqttTopic",Icon="fas fa-bullhorn"},
                         new MenuItem (){ Text="临时变量",Url="/DataSource/Variables",Icon="fas fa-key"},
                    }
                },
                 new MenuItem() { Text = "任务配置", Icon = "fa-solid fa-fw fa-table",IsCollapsed = false,
                    Items= new List<MenuItem>{
                         new MenuItem (){ Text="MQTT任务",Url="/DataSource/MqttStorage",Icon="fas fa-bullhorn",IsCollapsed = false,},
                         new MenuItem (){ Text="定时任务",Url="/DataSource/TaskConfig", Icon="fas fa-clock"},
                    }
                },
                  new MenuItem() { Text = "标准配置",Url="/DataStandard/DataStandardConfig", Icon = "fas fa-circle-nodes"},
                  new MenuItem() { Text = "测试", Icon = "fas fa-worm",IsCollapsed = false,
                    Items= new List<MenuItem>{
                         new MenuItem (){ Text="标准选择测试",Url="/DataStandard/DataStandardsSelect"},
                         new MenuItem (){ Text="自定义公式配置",Url="   /DataStandard/FormulaTest"},
                      
                    }
                },
            };//数据源管理

            var menus = new List<MenuItem>
            {
                new MenuItem() { Text = "数据源配置", Icon = "fa-solid fas fa-database", Url = "/api",Target="_blank" ,Items=menusDataSource},
                new MenuItem() { Text = "swagger", Icon = "fa-solid fas fa-eye", Url = "/api",Target="_blank" },
                 new MenuItem() { Text = "swagger", Icon = "fa-solid fas fa-eye", Url = "/DataCenter/DBConn" },
                new MenuItem() { Text = "返回组件库", Icon = "fa-solid fa-fw fa-home", Url = "https://www.blazor.zone/components",Target="_blank"  },
                new MenuItem() { Text = "Index", Icon = "fa-solid fa-fw fa-flag", Url = "/" , Match = NavLinkMatch.All},
                new MenuItem() { Text = "Counter", Icon = "fa-solid fa-fw fa-check-square", Url = "/counter",Target="_blank" },
                new MenuItem() { Text = "FetchData", Icon = "fa-solid fa-fw fa-database"},
                new MenuItem() { Text = "Table", Icon = "fa-solid fa-fw fa-table", Url = "table" },
                new MenuItem() { Text = "花名册", Icon = "fa-solid fa-fw fa-users", Url = "users" }
            };

            return menusDataSource;
        }
    }
}